feat(chatwoot): add support for WhatsApp catalog orderMessage#2393
Open
ValdecirMysian wants to merge 7 commits intoEvolutionAPI:mainfrom
Open
feat(chatwoot): add support for WhatsApp catalog orderMessage#2393ValdecirMysian wants to merge 7 commits intoEvolutionAPI:mainfrom
ValdecirMysian wants to merge 7 commits intoEvolutionAPI:mainfrom
Conversation
Added support for orderMessage in getTypeMessage method and updated message formatting for orders.
Refactor order message handling and improve formatting.
Implement cache for deduplication of order messages to avoid processing duplicates.
Contributor
Reviewer's GuideAdds WhatsApp Business catalog orderMessage support to the Chatwoot integration, including message-type detection, human-readable text formatting, and a small in-memory cache to deduplicate repeated order notifications. Class diagram for ChatwootService orderMessage supportclassDiagram
class ChatwootService {
-provider : any
-processedOrderIds : Map<string, number>
-ORDER_CACHE_TTL_MS : number
+getTypeMessage(msg : any) any
+getMessageContent(types : any) string
}
ChatwootService --> WAMonitoringService : uses
ChatwootService --> ConfigService : uses
Flow diagram for orderMessage handlingflowchart TD
A[Receive types map] --> B{typeKey is orderMessage}
B -- No --> Z[Return existing result]
B -- Yes --> C[Extract orderMessage]
C --> D[Clean cache older than ORDER_CACHE_TTL_MS]
D --> E{orderId already cached}
E -- Yes --> Y[Return undefined]
E -- No --> F[Cache orderId timestamp]
F --> G[Derive rawPrice from totalAmount1000]
G --> H[Format localized price]
H --> I[Assemble catalog order text]
I --> X[Return formatted response]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The hard-coded orderMessage text (including emojis and PT-BR strings) in
getMessageContentmakes this path locale-specific; consider reusing any existing localization/templating mechanism so catalog orders can be formatted per workspace/language configuration rather than fixed Portuguese. - The deduplication cache for
orderMessageis keyed only byorderId; if the same ID can appear across different senders/tenants, consider including sender or conversation identifiers in the key to avoid suppressing legitimate messages in other contexts. - The orderMessage cache cleanup only runs when processing a new orderMessage, so stale entries can accumulate if no further orders arrive; consider extracting this into a periodic cleanup or a helper called from a broader code path to keep the map bounded over time.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The hard-coded orderMessage text (including emojis and PT-BR strings) in `getMessageContent` makes this path locale-specific; consider reusing any existing localization/templating mechanism so catalog orders can be formatted per workspace/language configuration rather than fixed Portuguese.
- The deduplication cache for `orderMessage` is keyed only by `orderId`; if the same ID can appear across different senders/tenants, consider including sender or conversation identifiers in the key to avoid suppressing legitimate messages in other contexts.
- The orderMessage cache cleanup only runs when processing a new orderMessage, so stale entries can accumulate if no further orders arrive; consider extracting this into a periodic cleanup or a helper called from a broader code path to keep the map bounded over time.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Filtered null/undefined values from replyToIds before sending and constructed messageData object to include valid content_attributes.
Added LID to phone number mapping and resolution logic to handle LID addresses. Implemented caching for LID mappings and added methods to clean and save mappings.
Added handling for quoted product messages including price extraction and formatting.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds support for orderMessage (catalog orders) in the Chatwoot integration. Previously, catalog orders would appear as empty messages. This change ensures that the product title, price, and ID are correctly formatted and sent as text to Chatwoot.
Summary by Sourcery
Add support for WhatsApp Business catalog order messages in the Chatwoot integration and prevent duplicate order events from being sent.
New Features:
Bug Fixes: